
<%@page import="java.util.ArrayList"%>
<%@page import="bean.MboardVO"%>
<%@page import="bean.MboardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>view</title>
<link rel="stylesheet" href="../css/mboardview.css">
<script src="../js/mboard.js"></script>
</head>
<body>
<jsp:useBean id="vo" class="bean.MboardVO" scope="page"></jsp:useBean>
<jsp:setProperty property="*" name="vo"/>
<%
String m ="";
if(session.getAttribute("sessionMid")!=null){
	m = (String)session.getAttribute("sessionMid");
}
MboardDTO dto = new MboardDTO();
dto.setVo(vo);
//본문 글 정보 받아오기
MboardVO v = dto.selectone();
//이전 글 정보
MboardVO prev = dto.Precon();
//다음 글 정보
MboardVO nextv = dto.Nextcon();
//답글 정보
ArrayList<MboardVO> dap = dto.dap();
//조회수 컨트롤 본인 글에는 조회수가 올라가지 않는다.
if(session.getAttribute("sessionMid")!=null){
	if(session.getAttribute("sessionMid").equals(v.getMid())){
	}else{
	dto.viewcount(v.getVno());
	}
}else{
	dto.viewcount(v.getVno());
}
//글 레벨 확인
String [] t = v.getLev().split("-");
//파일 경로 받아오기
String path = request.getServletContext().getRealPath("/mboardfile");
String f = "";
if(v.getAttfile()!=null){
f = v.getAttfile();}
String filepath = path+"\\"+f;
%>
<br><br>
<div id = viewhead>
	<div id = viewrno>No.<%=v.getRno()%></div>
	<div id = viewcate>[ <%=v.getCategory() %> ]</div>
	<div id = viewtitle>제   목  : <%=v.getSubject()%></div>
	<div id = viewmid> 작성자 : <%=v.getMid()%></div>
</div><br>
<div id ="vcon"><pre><%=v.getContent()%></pre></div><p/>
<% if(t.length==1&&!f.equals("")){ %>
첨   부 : <a href="../../mboardfile/<%=f %>" download="<%=f%>"> <%=f%> </a><p/>

<%} %>
<%//<input type="button"value="다운로드" onclick="down('v.getAttfile()')"> %>

<input type="button" id="btnlist" value="목 록" class="viewbtn">

<%//본인글에만 해당 버튼이 보이도록 설정
if(session.getAttribute("sessionMid")!=null){
if(session.getAttribute("sessionMid").equals(v.getMid())){//본인 글에는 답글을 달수 없음-글-답글-답글에는 추가 답글을 달수 없음 
%>

<input type="button" id="btndel" value="삭 제" class="viewbtn">
<input type="button" id="btnmodi" value="수 정" class="viewbtn">
<input type="button" id="btninput" value="새 글 쓰 기" class="viewbtn">
<%}else if(t.length<3){ // 답글은 두번까지만 허용
%>
	<input type="button" id="btninputre" value="답 글 쓰 기" class="viewbtn">
	<input type="button" id="btninput" value="새 글 쓰 기" class="viewbtn">
<%} }else{
	%>
	<input type="button" id="btninput" value="새 글 쓰 기" class="viewbtn">
	<input type="button" id="btninputre" value="답 글 쓰 기" class="viewbtn">
	<%
}
//이전글 출력
if(prev.getRno()!=0){
	String afile = "";
	String wd = prev.getWdate().substring(0, 10);
	if(prev.getAttfile()!=null){
		afile = "[F] ";  
	}
%>

<br>

<div id = 'list_pre'>
	<div class ='list_title'>이전 ▲ : </div>
	<div class ='list_rno'><%=prev.getRno()%></div>
	<div class ='list_category'>[<%=prev.getCategory()%>]</div>
	<div class ='list_subject'><a href='#' onclick='goView(<%=prev.getRno()%>)'><%=afile%><%=prev.getSubject()%></a></div>
	<div class ='list_mid'><%=prev.getMid()%></div>
	<div class ='list_wdate'><%=wd%></div>
</div>

<%
}
if(dap.size()>1){ // 본문글에 연결된 답글 출력
	out.print("<br>");
	for(int a=0;a<dap.size();a++){
		MboardVO vv = dap.get(a);
		String subj = vv.getSubject();
		String [] tit= vv.getLev().split("-");
		String cfile = "";
		String wdd = vv.getWdate().substring(0, 10);
		if(vv.getAttfile()!=null){
			cfile = "[F] ";  
		}
		switch(tit.length){
		case 1 : break;
		case 2 : subj="&nbsp;&nbsp;┖"+subj; break;
		case 3 : subj="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┖"+subj;break;
		}
				
		%>
	<br>
	<div id = 'list_dap'>
		<div class ='list_title'></div>
		<div class ='list_rno'><%=vv.getRno()%></div>
		<div class ='list_category'>[<%=vv.getCategory()%>]</div>
		<div class ='list_subject'><a href='#' onclick='goView(<%=vv.getRno()%>)'><%=cfile%><%=subj%></a></div>
		<div class ='list_mid'><%=vv.getMid()%></div>
		<div class ='list_wdate'><%=wdd%></div>
	</div>
<%	}
	out.print("<br><br>");
}
if(nextv.getRno()!=0){ // 다음글 출력
	String bfile = "";
	String wdn = nextv.getWdate().substring(0, 10);
	if(nextv.getAttfile()!=null){
		bfile = "[F] ";  
	}
	
%>

<div id = 'list_next'>
	<div class ='list_title'>다음 ▼ : </div>
	<div class ='list_rno'><%=nextv.getRno()%></div>
	<div class ='list_category'>[<%=nextv.getCategory()%>]</div>
	<div class ='list_subject'><a href='#' onclick='goView(<%=nextv.getRno()%>)'><%=bfile%><%=nextv.getSubject()%></a></div>
	<div class ='list_mid'><%=nextv.getMid()%></div>
	<div class ='list_wdate'><%=wdn%></div>
</div>


<%} %>

<form name="viewfrm" method="post">
	<input type="hidden" name="rno" value="<%=vo.getRno()%>">
	<input type="hidden" name="lev" value="<%=v.getLev()%>">
	<input type="hidden" name="grp" value="<%=v.getGrp()%>">
	<input type="hidden" name="attfile" value="<%=v.getAttfile()%>">
	<input type="hidden" name="subject" value="<%=v.getSubject()%>">
	<input type="hidden" name="content" value="<%=v.getContent()%>">
	<input type="hidden" name="category" value="<%=v.getCategory()%>">
	<input type="hidden" name="nowpage" value="<%=vo.getNowpage()%>">
	<input type="hidden" name="find" value="<%=vo.getFind()%>">
	<input type="hidden" name="search" value="<%=vo.getSearch()%>">
	<input type="hidden" id="mid" name ="sid" value="<%=m%>">
</form>
<form name="listfrm" method="post">
	<input type="hidden" name="rno">
	<input type="hidden" name="search" value="<%=vo.getSearch()%>">
	<input type="hidden" name="find" value="<%=vo.getFind()%>">
	<input type="hidden" name="nowpage" value="<%=vo.getNowpage()%>">
</form>



<script>viewinit();</script>
</body>
</html> 